package com.zzxu.androiddemo01.button;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.zzxu.androiddemo01.R;
import com.zzxu.androiddemo01.utils.DateUtil;

public class ButtonEnableActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_demo;
    private TextView tv_result2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enable);
        Button btn_enable = findViewById(R.id.btn_enable);
        Button btn_ban = findViewById(R.id.btn_ban);
        btn_demo = findViewById(R.id.btn_demo);//设置全局变量ctrl+alt+f。封装这个属性，主要还是因为这两个属性是会影响控件状态的
        tv_result2 = findViewById(R.id.tv_result2);

        btn_demo.setOnClickListener(this);
        btn_ban.setOnClickListener(this);
        btn_enable.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
       switch (view.getId()){
           case R.id.btn_enable:
               btn_demo.setEnabled(true);
               btn_demo.setTextColor(Color.BLACK);
               break;
           case R.id.btn_ban:
               btn_demo.setEnabled(false);
               btn_demo.setTextColor(Color.GRAY);
               break;
           case  R.id.btn_demo:
               String desc = String.format("%s 您点击了按钮： %s", DateUtil.getNowTime(), ((Button) view).getText());
               tv_result2.setText(desc);

       }
    }
    
}
